package org.jvm.instruction.comparisons.dcmp;

import org.jvm.instruction.base.NoOperandsInstruction;
import org.jvm.rtda.thread.*;

/**
 * @author 海燕
 * @date 2023/1/29
 */
public abstract class DCMP extends NoOperandsInstruction {

    public void dcmpWithFlag(Frame frame, boolean gFlag) {
        OperandStack stack = frame.getOperandStack();
        double v2 = stack.popDouble();
        double v1 = stack.popDouble();

        if (v1 > v2) {
            stack.pushInt(1);
        } else if (v1 == v2) {
            stack.pushInt(0);
        } else if (v1 < v2) {
            stack.pushInt(-1);
        } else if (gFlag) {
            stack.pushInt(1);
        } else {
            stack.pushInt(-1);
        }
    }
}